Rem Build Version: 3.0.104.0
Rem Build Version: 3.0.89.0

@echo off
REM

REM   THIS CODE AND INFORMATION IS PROVIDED TO YOU FOR YOUR REFERENTIAL 
REM    PURPOSES ONLY, AND IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY REM  KIND, 
REM    EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
REM    WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE, 
REM    AND MAY NOT BE REDISTRIBUTED IN ANY MANNER.
REM 
REM    Copyright (c) Microsoft Corporation. All rights reserved.
REM
REM
REM   sample csv input file
REM
REM 
REM  MacAddress","machinename","Description","ProductKey","AdminPassword","Workgroup","Domain","DomainUsername","DomainPassword","Static_or_DHCP1","Nic_Name1","IPAddr1","Mask1","DefGW1","GWMetric1","DNS1","Static_or_DHCP2","Nic_Name2","IPAddr2","Mask2","DefGW2","GWMetric2","DNS2"
REM  "000000000002","Demo12gb","Demo 12gb drive","QK4D9-9F2YC-V9X88-738KT-7XF73","Nmuiop;'0","myworkgrp","mydomain","domainusr","domainpswd","static","Local Area Connection","192.168.5.10","255.255.255.0","192.168.5.1","1","192.168.5.1,192.168.5.2,192.168.5.3","static","Local Area Connection 2","192.168.7.1,192.168.7.2,192.168.7.3","255.255.255.0,255.255.255.0,255.255.255.0","192.168.7.100","2","192.168.5.1,192.168.5.2,192.168.5.3"
REM  "000000000401","mikemiltestvm31","mikes test machine","QK4D9-9F2YC-V9X88-738KT-7XF73","Nmuiop;'0","myworkgrp","mydomain","domainusr","domainpswd","static","Local Area Connection","192.168.5.11","255.255.255.0","192.168.5.1","1","192.168.5.1,192.168.5.2,192.168.5.3","static","Local Area Connection 2","192.168.7.1,192.168.7.2,192.168.7.3","255.255.255.0,255.255.255.0,255.255.255.0","192.168.7.100","2","192.168.5.1,192.168.5.2,192.168.5.3"
REM  "000000000402","mikemiltestvm32","mikes test machine","QK4D9-9F2YC-V9X88-738KT-7XF73","Nmuiop;'0","myworkgrp","mydomain","domainusr","domainpswd","static","Local Area Connection","192.168.5.12","255.255.255.0","192.168.5.1","1","192.168.5.1,192.168.5.2,192.168.5.3","static","Local Area Connection 2","192.168.7.1,192.168.7.2,192.168.7.3","255.255.255.0,255.255.255.0,255.255.255.0","192.168.7.100","2","192.168.5.1,192.168.5.2,192.168.5.3"
REM  "000000000403","mikemiltestvm33","mikes test machine","QK4D9-9F2YC-V9X88-738KT-7XF73","Nmuiop;'0","myworkgrp","mydomain","domainusr","domainpswd","static","Local Area Connection","192.168.5.13","255.255.255.0","192.168.5.1","1","192.168.5.1,192.168.5.2,192.168.5.3","static","Local Area Connection 2","192.168.7.1,192.168.7.2,192.168.7.3","255.255.255.0,255.255.255.0,255.255.255.0","192.168.7.100","2","192.168.5.1,192.168.5.2,192.168.5.3"


setlocal
if "%1" == "" goto usage
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

for /f "skip=1 usebackq tokens=1,* delims=," %%a in (%1) do (
	call :add-device  %%a %%b %%c %%d %%e %%f %%g %%h %%i %%j %%k %%l %%m %%n %%o %%p %%q %%r %%s %%t %%u %%v %%w %%x %%y %%z
)

Goto end_add-device


:add-device
setlocal
set macaddr=%1
Shift
set machinename=%1
Shift
Set Desc=%1
Shift
Set ProductKey=%1
Shift
Set Adminpassword=%1
shift
Set Workgroup=%1
shift
Set Domain=%1
shift
Set Domainusername=%1
shift
Set DomainPassword=%1
shift
set Static_or_DHCP1=%1
shift
Set Nic_name1=%1
shift
Set IpAddr1=%1
shift
Set Mask1=%1
shift
Set DefGW1=%1
shift
Set GWMetric1=%1
shift
Set DNS1=%1
shift
set Static_or_DHCP2=%1
Shift
Set Nic_name2=%1
shift
Set IpAddr2=%1
shift
Set Mask2=%1
shift
Set DefGW2=%1
shift
Set GWMetric2=%1
shift
Set DNS2=%1

ADSDevice /add %machinename% /description %desc% /adminmac %macaddr%

@echo.
@Echo DEVICE=%machinename%
@echo.

ADSDevice /edit %machinename% /setvar   machinename %machinename%
echo..
ADSDevice /edit %machinename% /setvar   ProductKey %ProductKey%  
echo..
ADSDevice /edit %machinename% /setvar   Adminpassword %Adminpassword% 
echo...
ADSDevice /edit %machinename% /setvar   Workgroup %WorkGroup% 
echo...
ADSDevice /edit %machinename% /setvar   Domain %Domain% 
echo....
ADSDevice /edit %machinename% /setvar   Domainusername %Domainusername% 
echo.....
ADSDevice /edit %machinename% /setvar   DomainPassword %DomainPassword% 
echo......
ADSDevice /edit %machinename% /setvar   Static_or_DHCP1 %Static_or_DHCP1% 
echo.......
ADSDevice /edit %machinename% /setvar   Nic_name1 %Nic_name1% 
echo........
ADSDevice /edit %machinename% /setvar   IpAddr1 %IpAddr1% 
echo.........
ADSDevice /edit %machinename% /setvar   Mask1 %Mask1% 
echo..........
ADSDevice /edit %machinename% /setvar   DefGW1 %DefGw1%
echo...........
ADSDevice /edit %machinename% /setvar   GWMetric1 %GWMetric1% 
echo............
ADSDevice /edit %machinename% /setvar   DNS1 %DNS1% 
echo.............
ADSDevice /edit %machinename% /setvar   Static_or_DHCP2 %Static_or_DHCP2% 
echo..............
ADSDevice /edit %machinename% /setvar   Nic_name2 %Nic_name2% 
echo...............
ADSDevice /edit %machinename% /setvar   IpAddr2 %IpAddr2% 
echo................
ADSDevice /edit %machinename% /setvar   Mask2 %Mask2% 
echo.................
ADSDevice /edit %machinename% /setvar   DefGW2 %DefGw2% 
echo..................
ADSDevice /edit %machinename% /setvar   GWMetric2 %GWMetric2% 
echo...................
ADSDevice /edit %machinename% /setvar   DNS2 %DNS2% 

:end_add-device

endlocal
goto end

:usage
@echo.
echo usage: bulkimport import_file.csv
@echo.

:end
